package util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.sql.DataSource;


public class DBUtil {
	private static Connection con;
	private static DataSource ds;
	public static Connection createConnection(){
		try {
			InitialContext cxt = new InitialContext();
		    ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/myoracle" );
			con = ds.getConnection();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	
	public static void close(Connection con,PreparedStatement pst,ResultSet rs){
		try {
			if(con!=null)
			con.close();
			if(pst!=null)
			pst.close();
			if(rs!=null)
			rs.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
